package cz.ctu.guiproject.client.formvalidation;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.validator.routines.InetAddressValidator;

import static cz.ctu.guiproject.client.resources.constants.Constants.*;

import android.widget.EditText;

public class ValidationService {

	public static boolean isValidIPv4(EditText editText) {
		final InetAddressValidator addrValidator = InetAddressValidator.getInstance();
		if (addrValidator.isValidInet4Address(editText.getText().toString())) {
			editText.setError(null);
			return true;
		} else {
			editText.setError(INVALID_IPV4_MESSAGE);
			return false;
		}
	}

	public static boolean isNotNull(EditText editText) {
		if (StringUtils.isBlank(editText.getText())) {
			editText.setError(NULL_VALUE_MESSAGE);
			return false;
		} else {
			editText.setError(null);
			return true;
		}
	}
}
